import logging

import pytest

from resource.pom.settings import Settings
from utils.manager import Images


class Test:
    app = Settings

    @pytest.mark.parametrize('setup_teardown', [app.bundle_name], indirect=True)
    def test(self, setup_teardown, device):
        logging.info('步骤1.点击设置应用')
        device.start_ability(self.app.bundle_name, self.app.ability_name)
        logging.info('预期结果1.进入设置应用')
        device.assert_current_window(self.app.window_name)

        logging.info('步骤2.点击移动网络')
        device.click(*self.app.mobile_network_item)
        logging.info('预期结果2.进入移动网络页面')
        device.refresh_layout()
        device.assert_text_exist('移动数据')

        logging.info('步骤3.点击移动数据')
        device.click_element(device.get_element_by_text('移动数据'))
        logging.info('预期结果3.进入移动数据页面')
        device.wait(2)
        device.assert_current_window(self.app.call_win)
        current_page = device.save_snapshot_to_local('mobile_data.jpeg')
        Images.crop_picture(current_page)
        similarity = Images.compare_image_similarity(current_page, self.app.mobile_data_page)
        assert similarity > 0.9, '当前界面和标准图相似度差距过大'
